﻿/*
 * @file: MD5Encrypt.cs
 * @in namespace: Encrypt
 */
using System;

/// <summary>
/// Summary description for MD5Encrypt
/// </summary>
namespace Encrypt
{
    public class MD5Encrypt
    {
        /// <summary>
        /// Encrypt string with MD5 algorithm
        /// </summary>
        /// <param name="Input">String to encrypt</param>
        /// <returns>string encrypted</returns>
        public static string GetMD5Hash(string Input)
        {
            System.Text.StringBuilder result = new System.Text.StringBuilder();

            try
            {
                System.Security.Cryptography.MD5CryptoServiceProvider md5Provider = new System.Security.Cryptography.MD5CryptoServiceProvider();
                byte[] bs = System.Text.Encoding.UTF8.GetBytes(Input);
                bs = md5Provider.ComputeHash(bs);

                foreach (byte b in bs)
                {
                    result.Append(b.ToString("x2").ToLower());
                }
            }
            catch (Exception ex) {
                throw ex;
            }
            return result.ToString();
        }

        public MD5Encrypt()
        {
            //
            // TODO: Add constructor logic here
            //
        }
    }
}